package com.share.one;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.Test;

public class Receiver_1 {
	
	@Test
	public void test() throws Exception{
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
				"sunxj", 
				"123123", 
				"tcp://localhost:61616");
		Connection connection = connectionFactory.createConnection();
		connection.start();
		Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
		Destination destination = session.createQueue("test1_queue");
		MessageConsumer messageConsumer = session.createConsumer(destination);
		
		while (true) {
			TextMessage textMessage = (TextMessage) messageConsumer.receive();
			textMessage.acknowledge();//session采用非事务，且消息签收模式采用CLIENT_ACKNOWLEDGE
			if (textMessage == null) {
				break;
			}
			System.out.println("消费者： " + textMessage.getText());
		}
		
		
		if (connection != null) {
			connection.close();
		}
	}

}
